1. Field of the Invention
The present invention generally relates to multi-threaded processing and more specifically to simultaneous submission to a multi-producer queue by multiple threads.
2. Description of the Related Art
During execution of a program by a multi-threaded processor, data generated by the program may be output by producer threads to a shared queue that is read by one or more consumer threads. The sections of the queue that contain valid data need to be indicated so that only valid data is read by the consumer threads. One conventional mechanism that ensures only valid data is read by consumer threads uses a per-entry or per-section “valid” bit that is set by the producer threads when the valid data is written and cleared by the consumer threads when the valid data is read. A drawback of using a per-entry or per-section “valid” bit is that the bit must be stored separately or in the queue and explicitly queried to determine whether or not each entry or section of the queue may be safely read.
A second conventional mechanism maintains a single “valid” pointer to an entry in the queue, behind which all data stored in the queue is valid and may be safely read by the consumer threads. When multiple producers may write the queue, care is required to maintain the “valid” pointer so that only “valid” data is stored behind the “valid” pointer. The multiple producers may be constrained to write the queue serially.
Accessing the shared queue may be further complicated if the producers may write data to the queue out of order. When multiple threads output without any coordination, the resulting data may be an unintelligible mix of data generated by the multiple threads as the program is executed.
Accordingly, what is needed in the art is an improved system and method for ensuring that multiple producer threads may simultaneously write entries in a shared queue and one or more consumers may read valid data from the shared queue. Importantly, writing of the shared queue by the multiple producer threads should not be serialized and the one or more consumer threads may read the shared queue while the producer threads write the shared queue.